		<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Strict//EN" "http://www.w3.org/TR/html4/strict.dtd">
		<html>
		<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
		<meta http-equiv="pragma" content="no-cache">
		<meta http-equiv="cache-control" content="no-cache">
		<meta http-equiv="expires" content="0"><meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
		<title>Welcome to Design Zone......</title>
		<link rel="stylesheet" type="text/css"
			href="../../scripts/ext/resources/css/ext-all.css" />
		<link rel="stylesheet" type="text/css"
			href="../../scripts/ext/resources/css/file-upload.css" />
		<link rel="stylesheet" type="text/css" href="../../styles/dzbase.css" />
		<script type="text/javascript"
			src="../../scripts/ext/adapter/ext-base.js">
		        </script>
		<script type="text/javascript" src="../../scripts/ext/ext-all.js">
        </script>
        <script type="text/javascript" src="../../scripts/grid/GroupSummary.js">
        </script>
		<script type="text/javascript" src="../../scripts/menu/EditableItem.js">
		        </script>
		<script type="text/javascript" src="../../scripts/menu/RangeMenu.js">
		        </script>
		<script type="text/javascript" src="../../scripts/grid/GridFilters.js">
		        </script>
		<script type="text/javascript" src="../../scripts/grid/filter/Filter.js">
		        </script>
		<script type="text/javascript"
			src="../../scripts/grid/filter/StringFilter.js">
        </script>
		<script type="text/javascript"
			src="../../scripts/grid/filter/ListFilter.js">
        </script>
		<script type="text/javascript"
			src="../../scripts/grid/filter/DateFilter.js"></script>
		<script type="text/javascript" src="../../scripts/grid/RowExpander.js">
        </script>
		<script type="text/javascript" src="../../scripts/form/FileUploadField.js">
        </script>
        <script type="text/javascript" src="../../scripts/grid/RowExpander.js">
        </script>
		<script type="text/javascript" src="../../scripts/i18nMessage.js">
        </script>
		<script type="text/javascript" src="../../scripts/utils.js">
        </script>
		<script type="text/javascript"
			src="../../scripts/selectMeasureSpecification.js">
        </script>
		<script type="text/javascript"
			src="../../scripts/multiSelectProductIdentification.js">
        </script>
		<script type="text/javascript" src="../../scripts/selectBiFactory.js">
        </script>
		<script type="text/javascript"
			src="../../scripts/selectBiFranceCustomer.js">
        </script>
		<script type="text/javascript" src="../../scripts/selectBiArmor.js">
        </script>
		<script type="text/javascript" src="../../scripts/selectDzColor.js">
        </script>
        <script type="text/javascript" src="../../scripts/selectYarn.js">
        </script>
		<script type="text/javascript">
            var piMessage = new i18nMessage('../../servlet/I18nMessageServlet?keyPrefix=ui.productidentification');
            var msMessage = new i18nMessage('../../servlet/I18nMessageServlet?keyPrefix=ui.measurespecification');
            var dzColorMessage = new i18nMessage('../../servlet/I18nMessageServlet?keyPrefix=ui.dzcolor');
			var referenceMessage = new i18nMessage('../../servlet/I18nMessageServlet?keyPrefix=ui.reference');
			var fcMessage = new i18nMessage('../../servlet/I18nMessageServlet?keyPrefix=ui.francecustomer');
			var fMessage = new i18nMessage('../../servlet/I18nMessageServlet?keyPrefix=ui.factory');
			var orderMessage = new i18nMessage('../../servlet/I18nMessageServlet?keyPrefix=ui.order');
            var message = new i18nMessage('../../servlet/I18nMessageServlet?keyPrefix=message');
            
            var idValue = getPrarmeterValue(window.location, 'id');
            var startPage = getPrarmeterValue(window.location, 'startPage');
			var input = getPrarmeterValue(window.location, 'input');
            
            var ctYesnoXmlLoader = new xmlLoader('../../servlet/CodeTableServlet?name=CtYesno');
            var variantXmlLoader = new xmlLoader('../../servlet/ProductIdentificationServlet?action=300&id=' + idValue);
			
			var pLaunchingListStore;
            var pLaunchingListGrid;
            
            var ctYesnoStore;
            var variantStore;
            
            var isSwatchCombo;
            var variantCombo;
            
            var validateWin;
            
            ctYesnoStore = new Ext.data.Store({
                   
                    reader: new Ext.data.XmlReader({
                        record: 'item',
                        id: 'code',
                        totalRecords: 'itemTotal'
                    }, [
                    'code', 'description']),
					data: ctYesnoXmlLoader.getXml()
                });
                
            variantStore = new Ext.data.Store({
                   
                    reader: new Ext.data.XmlReader({
                        record: 'item',
                        id: 'code',
                        totalRecords: 'itemTotal'
                    }, [
                    'code', 'description']),
					data: variantXmlLoader.getXml()
                });
                
            
            isSwatchCombo = new Ext.form.ComboBox({
					fieldLabel: message.get('message.edit.swatch'),
					id: 'isSwatch',
					name: 'isSwatch',
					editable: false,
					valueField: 'code',
				    store: ctYesnoStore,
				    displayField:'description',
				    triggerAction: 'all',
				    emptyText: message.get('message.combo.pleaseselect'),
				    selectOnFocus:true,
				    allowBlank: false,
					mode: 'local',
					anchor: '60%',
					listeners: {
						select: {
							fn: function (thisComb, record,index){
								var isSwatch = isSwatchCombo.getValue();
								if(isSwatch == '01'){
									Ext.getCmp('quantity2').enable();
								}else if(isSwatch == '02'){
									Ext.getCmp('quantity2').disable();
								}
							}
						}
					}
				});
				
			 variantCombo = new Ext.form.ComboBox({
					fieldLabel: dzColorMessage.get('ui.dzcolor.variant'),
					id: 'variant',
					name: 'variant',
					editable: false,
					valueField: 'code',
				    store: variantStore,
				    displayField:'description',
				    triggerAction: 'all',
				    allowBlank: false,
				    emptyText: message.get('message.combo.pleaseselect'),
				    selectOnFocus:true,
					mode: 'local',
					anchor: '60%'
				});
				
			var productDZColorXMLReader = new Ext.data.XmlReader({
                record: 'item'
            }, [{
                name: 'id',
                mapping: 'id'
            },{
            	name: 'sequence',
            	mapping: 'sequence'
            },{
            	name: 'variant',
            	mapping: 'variant'
            },{
                name: 'dzColorId',
                mapping: 'dzColorId'
            },{
                name: 'dzColorCode',
                mapping: 'dzColorCode'
            },{
                name: 'yarnReference',
                mapping: 'yarnReference'
            },{
                name: 'ctYarnMeasure',
                mapping: 'ctYarnMeasure'
            },{
                name: 'yarnAccount',
                mapping: 'yarnAccount'
            },{
                name: 'ctYarnMaterial1',
                mapping: 'ctYarnMaterial1'
            },{
                name: 'ctYarnMaterial2',
                mapping: 'ctYarnMaterial2'
            },{
                name: 'ctYarnMaterial3',
                mapping: 'ctYarnMaterial3'
            },{
                name: 'ctYarnMaterial4',
                mapping: 'ctYarnMaterial41'
            },{
                name: 'ctYarnMaterial5',
                mapping: 'ctYarnMaterial5'
            },{
                name: 'customerColorCode',
                mapping: 'customerColorCode'
            },{
                name: 'percentage',
                mapping: 'percentage'
            },{
                name: 'loss',
                mapping: 'loss'
            },{
                name: 'actualWeight',
                mapping: 'actualWeight'
            },{
                name: 'factoryName',
                mapping: 'factoryName'
            },{
				name: 'photo3Name',
				mapping: 'photo3Name'
            }]);
			
            var piXMLReader = new Ext.data.XmlReader({
                   record: 'item'
               }, [{
                   name: 'id',
                   mapping: 'id'
               }, {
                   name: 'ctProductFamily',
                   mapping: 'ctProductFamily'
               }, {
                   name: 'ctMachineType',
                   mapping: 'ctMachineType'
               }, {
                   name: 'ctStatureCode',
                   mapping: 'ctStatureCode'
               }, {
                   name: 'type',
                   mapping: 'type'
               }, {
                   name: 'orderNumber',
                   mapping: 'orderNumber'
               }, {
                   name: 'yarnNumber',
                   mapping: 'yarnNumber'
               }, {
                   name: 'ctDesignType',
                   mapping: 'ctDesignType'
               }, {
                   name: 'style',
                   mapping: 'style'
               }, {
                   name: 'customerLinkman',
                   mapping: 'customerLinkman'
               }, {
                   name: 'model',
                   mapping: 'model'
               }, {
                   name: 'ctSeasonNumber',
                   mapping: 'ctSeasonNumber'
               }, {
                   name: 'ctSeasonNumberCode',
                   mapping: 'ctSeasonNumberCode'
               }, {
                   name: 'reference',
                   mapping: 'reference'
               }, {
                   name: 'createDate',
                   mapping: 'createDate'
               }, {
                   name: 'ctVersion',
                   mapping: 'ctVersion'
               }, {
                   name: 'patronageNumer',
                   mapping: 'patronageNumer'
               }, {
                   name: 'front',
                   mapping: 'front'
               }, {
                   name: 'back',
                   mapping: 'back'
               }, {
                   name: 'sleeves',
                   mapping: 'sleeves'
               }, {
                   name: 'bottomThrum',
                   mapping: 'bottomThrum'
               }, {
                   name: 'sleevesThrum',
                   mapping: 'sleevesThrum'
               }, {
                   name: 'necklineThrum',
                   mapping: 'necklineThrum'
               }, {
                   name: 'needle',
                   mapping: 'needle'
               }, {
                   name: 'weight',
                   mapping: 'weight'
               }, {
                   name: 'comment',
                   mapping: 'comment'
               }, {
                   name: 'customerID',
                   mapping: 'customerID'
               }, {
                   name: 'photoName',
                   mapping: 'photoName'
               }, {
                   name: 'chartName',
                   mapping: 'chartName'
               }, {
                   name: 'biMeasureSpecificationId',
                   mapping: 'biMeasureSpecificationId'
               }, {
                   name: 'biMeasureSpecificationName',
                   mapping: 'biMeasureSpecificationName'
               }, {
                   name: 'yarnName',
                   mapping: 'yarnName'
               }, {
                   name: 'frontPhotoName',
                   mapping: 'frontPhotoName'
               }, {
                   name: 'backPhotoName',
                   mapping: 'backPhotoName'
               }, {
                   name: 'photoName',
                   mapping: 'photoName'
               }, {
                   name: 'chartName',
                   mapping: 'chartName'
               }, {
                   name: 'ctCollarType',
                   mapping: 'ctCollarType'
               },{
               	   name: 'ctProductIdentificationStyle',
               	   mapping: 'ctProductIdentificationStyle'
               },{
                   name: 'customerName',
                   mapping: 'customerName'
               }, {
                   name: 'customerDepartment',
                   mapping: 'customerDepartment'
               }, {
                   name: 'referenceAs',
                   mapping: 'referenceAs'
               }, {
                   name: 'createDate',
                   mapping: 'createDate'
               },{
               	   name: 'sketch1Name',
               	   mapping: 'sketch1Name'
               },{
               	   name: 'sketch2Name',
               	   mapping: 'sketch2Name'
               },{
               	   name: 'sketch3Name',
               	   mapping: 'sketch3Name'
               },{
               	   name: 'scheduleDate',
               	   mapping: 'scheduleDate'
               },{
               	   name: 'quantity',
               	   mapping: 'quantity'
               },{
               	   name: 'stockDate',
               	   mapping: 'stockDate'
               },{
               	   name: 'quantityConsistent',
               	   mapping: 'quantityConsistent'
               },{
               	   name: 'quantityNotConsistent',
               	   mapping: 'quantityNotConsistent'
               },{
               	   name: 'biFactoryId',
               	   mapping: 'biFactoryId'
               },{
               	   name: 'biFactoryName',
               	   mapping: 'biFactoryName'
               }]);
                
              var piXmlLoader = new xmlLoader('../../servlet/ProductIdentificationServlet?action=11&id=' + idValue);
              
              var piRecord = piXMLReader.readRecords(piXmlLoader.getXml()).records[0];
              
              var itemTplMarkup = ['<table cellspacing="0" id="the-table" style="width: 100%;"><tbody>',
								 '<tr><td style="background:#eeeeee; width: 15%;">',
								 fcMessage.get('ui.francecustomer.name'), 
								 '</td><td>{customerName}</td>', 
								 '<td style="background:#eeeeee;width: 15%;">', 
								 fcMessage.get('ui.francecustomer.department'), 
								 '</td><td>{customerDepartment}</td><td style="background:#eeeeee;">', 
								 piMessage.get('ui.productidentification.seasonnumber'), 
								 '</td><td>{ctSeasonNumber}</td>', '<td style="background:#eeeeee;">', 
								 message.get('message.edit.createdate') + '(d/m/Y)', 
								 '</td><td>{createDate}</td></tr>', 
								 
								 
								 '<tr><td style="background:#eeeeee;">', 
								referenceMessage.get('ui.reference.reference'),
								 '</td><td>{reference}</td><td style="background:#eeeeee;">', 
								piMessage.get('ui.productidentification.style'), 
								 '</td><td>{ctCollarType}&nbsp;&nbsp;{ctProductIdentificationStyle}</td><td style="background:#eeeeee;">', 
								 piMessage.get('ui.productidentification.chartversion'), 
								 '</td><td>{ctVersion}</td><td style="background:#eeeeee;">', 
								piMessage.get('ui.productidentification.designtype'), 
								 '</td><td>{ctDesignType}</td></tr>',
								 
								 '<tr><td colspan="8">',
								 //'<img width="120" src="../../_temp/{frontPhotoName}"/>&nbsp;&nbsp;&nbsp;&nbsp;',
								 //'<img width="120" src="../../_temp/{backPhotoName}"/>&nbsp;&nbsp;&nbsp;&nbsp;',
								 '<img width="120" src="../../_temp/{sketch1Name}"/>&nbsp;&nbsp;&nbsp;&nbsp;',
								 '<img width="120" src="../../_temp/{sketch2Name}"/>&nbsp;&nbsp;&nbsp;&nbsp;',
								 '<img width="120" src="../../_temp/{sketch3Name}"/>',
								 '</td></tr>',
								 '</tbody></table>'];
              var itemTpl = new Ext.Template(itemTplMarkup);
              
              
              var selectDZColorCallback = function(dzColorId, dzColorCode, customerName, customerDepartment, yarnReference, ctYarnMeasure, yarnAccount,
						supplierNumber, customerColorCode, pantoneNumber, realColor,
						ctYarnMaterial1, ctYarnMaterial2, ctYarnMaterial3, ctYarnMaterial4, ctYarnMaterial5, factoryName, photo1Name, photo2Name,isApproved){
					if(isApproved == '02'){
						messageTip.msg(message.get('message.tip'), orderMessage.get('ui.order.colornotapproved'));
						return;
					}
					Ext.getCmp('dzColorId').setValue(dzColorId);
					Ext.getCmp('dzColorCode').setValue(dzColorCode);
					//Ext.getCmp('customerName').setValue(customerName);
					//Ext.getCmp('customerDepartment').setValue(customerDepartment);
					
					//Ext.getCmp('supplierNumber').setValue(supplierNumber);
					Ext.getCmp('customerColorCode').setValue(customerColorCode);
					//Ext.getCmp('pantoneNumber').setValue(pantoneNumber);
					//if(realColor && realColor != '')
					//	document.getElementById('sampleTable').style['backgroundColor'] = '#' + realColor;
					//else
					//	document.getElementById('sampleTable').style['backgroundColor'] = '#DFE8F6';
					//Ext.getCmp('factoryName').setValue(factoryName);
				}
				
				var editCallback = function(){
					pLaunchingForm.getForm().load({
						url:'../../servlet/ProductLaunchingServlet?action=3&id=' + editId, 
						waitMsg:Ext.LoadMask.prototype.msg, 
						success: function(form, action){
							isSwatchCombo.fireEvent('select');
							
						},
						failure: function(o){
							messageTip.msg(message.get('message.tip'), message.get('message.load.unsuccessful'));
						}
					});
				}
				
				var deleteCallback = function(btn){
	                if (btn == 'yes') {
	                    Ext.Ajax.request({
	                        url: '../../servlet/ProductLaunchingServlet?action=2&id=' + deleteId,
	                        success: function(o){
	                            if (o.responseText == 'success') {
	                                pLaunchingListStore.reload();
	                                messageTip.msg(message.get('message.tip'), message.get('message.delete.successful'));
	                            }
	                            else {
	                                messageTip.msg(message.get('message.tip'), message.get('message.delete.unsuccessful'));
	                            }
	                        },
	                        failure: function(o){
	                            messageTip.msg(message.get('message.tip'), message.get('message.delete.failure'));
	                        },
	                        params: {
	                            foo: 'bar'
	                        }
	                    });
	                }
	            }

	            var addToStock = function(id, isStock){
		            if(isStock == '01'){
			            isStock = '02';
		            }else{
		            	isStock = '01';
		            }
	            	Ext.Ajax.request({
                        url: '../../servlet/ProductLaunchingServlet?action=30&id=' + id + '&isStock=' + isStock,
                        success: function(o){
                            if (o.responseText == 'success') {
                                pLaunchingListStore.reload();
                                messageTip.msg(message.get('message.tip'), message.get('message.operation.successful'));
                            }
                            else {
                                messageTip.msg(message.get('message.tip'), message.get('message.operation.unsuccessful'));
                            }
                        },
                        failure: function(o){
                            messageTip.msg(message.get('message.tip'), message.get('message.operation.unsuccessful'));
                        },
                        params: {
                            foo: 'bar'
                        }
                    });
		        }
	            
	            var selectYarnId;
	            var selectYarnCallback = function(yarnId, yarnReference, factoryName, ctYarnMaterial1, ctYarnMaterial2, ctYarnMaterial3, ctYarnMaterial4, ctYarnMaterial5,ctYarnMeasure,yarnAccount){
					//alert(yarnId + ' ' + factoryName + ' ' +yarnReference+ ' ' +ctYarnMaterial1+ ' ' +ctYarnMaterial2+ ' ' +ctYarnMaterial3+ ' ' +ctYarnMaterial4+ ' ' +ctYarnMaterial5);
					selectYarnId = yarnId;
					document.getElementById('yarnReference').value = yarnReference;
					document.getElementById('factoryName').value = factoryName;
					document.getElementById('ctYarnMaterial1').value = ctYarnMaterial1;
					document.getElementById('ctYarnMaterial2').value = ctYarnMaterial2;
					document.getElementById('ctYarnMaterial3').value = ctYarnMaterial3;
					document.getElementById('ctYarnMaterial4').value = ctYarnMaterial4;
					document.getElementById('ctYarnMaterial5').value = ctYarnMaterial5;
					Ext.getCmp('yarnAccount').setValue(ctYarnMeasure + ' ' + yarnAccount);
				}
				
				var calWeight = function(quantity1, quantity2){
					var weight = piRecord.data.weight;
                   	var totalWeight = weight * quantity1;
                   	if(quantity2 != ''){
                   		totalWeight += quantity2 * 0.1;
                   	}
                   	return  render3D(totalWeight);
				}

				//alert(piRecord.data.ctStatureCode);
				var sizes;
				if('04' != piRecord.data.ctStatureCode){
					sizes = getMeasureSpecificationItemName(piRecord.data.ctStatureCode);
				}else{
					sizes = ['S1', 'S2', 'M1', 'M2', 'L1', 'L2'];
				}
				
				var sizeArray = new Array();
            
	            var forSizeStore = new Ext.data.Store({
	                   
	                    reader: new Ext.data.XmlReader({
	                        record: 'item',
	                        id: 'code',
	                        totalRecords: 'itemTotal'
	                    }, [
	                    'code', 'description']),
						data: []
	                });
                
           
            for(var i = 0; i < sizes.length; i ++){
                if(sizes[i] != ''){
	            	var newRecord = new Ext.data.Record();
					newRecord.data = new Array();
					newRecord.set('code', sizes[i]);
					newRecord.set('description', sizes[i]);  
	            	sizeArray.push(newRecord);
                }
            }
             forSizeStore.add(sizeArray);
			var forSizeCombo = new Ext.form.ComboBox({
					fieldLabel: msMessage.get('ui.measurespecification.size'),
					id: 'size',
					name: 'size',
					editable: false,
					valueField: 'code',
				    store: forSizeStore,
				    displayField:'description',
				    anchor: '76%',
					width: '80%',
				    triggerAction: 'all',
				    emptyText: message.get('message.combo.pleaseselect'),
					allowBlank: false,
                    blankText: message.get('message.edit.noblank'),
				    selectOnFocus:true,
					mode: 'local'
				});
			
			
              Ext.onReady(function(){
				itemTpl.append('productIdentification', piRecord.data);
				
                Ext.QuickTips.init();
                Ext.form.Field.prototype.msgTarget = 'side';
				
				pLaunchingListStore = new Ext.data.GroupingStore({
                    url: '../../servlet/ProductLaunchingServlet?action=5&id=' + idValue,
                    
                    reader: new Ext.data.XmlReader({
                        record: 'item',
                        id: 'id',
                        totalRecords: 'itemTotal'
                    }, ['index', 'id', 'size', 'variant', 'isSwatch','color','isStock','scheduleDate','stockDate','biFactoryId','factoryNameCN','factoryNameEN',
						{
							name:'quantity1',
							type: 'int'
						},{
							name:'quantity2',
							type: 'int'
						},{
							name:'quantity',
							type: 'int'
						},{
							name:'quantityConsistent',
							type: 'int'
						},{
							name:'quantityNotConsistent',
							type: 'int'
						}]),
                    
						groupField: 'variant',
		                    
	                    sortInfo:{
	                    	field: 'index',
	                    	direction: 'ASC'
	                    },
	                    remoteSort: false
                });
				
				var expander = new Ext.grid.RowExpander({
			        tpl : new Ext.XTemplate(
					    '{[this.getDZColor(values.id, values.quantity1, values.quantity2)]}',{
							getDZColor:function(id, quantity1, quantity2){
								var variantXmlLoader = new xmlLoader('../../servlet/ProductLaunchingServlet?action=20&id=' + id);
								var variantRecords = productDZColorXMLReader.readRecords(variantXmlLoader.getXml()).records;
								var html = '<br/><table cellspacing="0" id="the-table" style="width: 70%;margin-left: 50px;"><tr>';
								html += ('<td style="background:#eeeeee;">' + dzColorMessage.get('ui.dzcolor.customercolorcode') + '</td>');
								html += ('<td style="background:#eeeeee;">' + dzColorMessage.get('ui.dzcolor.code') + '</td>');
								html += ('<td style="background:#eeeeee;">' + yarnMessage.get('ui.yarn.reference') + '</td>');
								html += ('<td style="background:#eeeeee;">' + dzColorMessage.get('ui.dzcolor.percentage') + '(%)</td>');
								html += ('<td style="background:#eeeeee;">' + orderMessage.get('ui.order.isyarnneeded') + '(Kg)</td>');
								html += '</tr>';
								
								for(var i = 0; i < variantRecords.length; i ++){
									var record = variantRecords[i];
									html += '<tr>';
									html += ('<td>' + record.data.customerColorCode + '</td>');
									html += ('<td>' + record.data.dzColorCode + '</td>');
									html += ('<td>' + record.data.yarnReference + '</td>');
									html += ('<td style="text-align: right;">' + record.data.percentage + '</td>');
									html += ('<td style="text-align: right;">' + render3D(calWeight(quantity1, quantity2)*record.data.percentage/100) + '</td>');
									html += '</tr>';
								}
								
								html += '</table><br/>'
								
					         	return html;
					     	}
						}
			        )
			    });

				var summary = new Ext.grid.GroupSummary();
				pLaunchingListGrid = new Ext.grid.GridPanel({
                    title: piMessage.get('ui.productidentification.listlaunching'),
                    store: pLaunchingListStore,
                    stripeRows: true,
                    plugins: [summary, expander],
                    height: 360,
                    columns: [expander,{
                        header: message.get('message.list.id'),
                        width: 20,
                        dataIndex: 'index',
                        sortable: false
                    },{
                        header: dzColorMessage.get('ui.dzcolor.variant'),
                        dataIndex: 'variant',
                        width: 20,
                        sortable: false
                    },{
                        header: msMessage.get('ui.measurespecification.size'),
                        dataIndex: 'size',
                        width: 20,
                        sortable: false
                    },{
                        header: piMessage.get('ui.productidentification.quantitysweater'),
                        dataIndex: 'quantity1',
                        width: 20,
                        sortable: false,
                        summaryType:'sum'
                    },{
                        header: message.get('message.edit.swatch') + '?',
                        dataIndex: 'isSwatch',
                        width: 20,
                        sortable: false,
                        renderer: renderIsYesno
                    },{
                        header: piMessage.get('ui.productidentification.quantityswatch'),
                        dataIndex: 'quantity2',
                        width: 20,
                        sortable: false,
                        summaryType:'sum'
                    },{
                        header: orderMessage.get('ui.order.isyarnneeded') + '(Kg)',
                        dataIndex: 'yarnNeeded',
                        width: 20,
                        align:'right',
                        renderer : function(value, p, record){
                        	return  calWeight(record.data.quantity1, record.data.quantity2);
                        },
                        summaryType:'sum'
                    },{
                        header: piMessage.get('ui.productidentification.scheduledate')+'(d/m/y)',
                        width: 20,
                        dataIndex: 'scheduleDate'
                    },{
                        header: piMessage.get('ui.productidentification.cquantity'),
                        width: 20,
                        dataIndex: 'quantityConsistent'
                    },{
                        header: message.get('message.action.validator'),
                        dataIndex: 'id',
                        width: 20,
                        renderer: renderValidate
                    }],
                    view: new Ext.grid.GroupingView({
                        forceFit: true,
						hideGroupedColumn: true,
						enableNoGroups:false,
                        groupTextTpl: '&nbsp;&nbsp;<b>' + dzColorMessage.get('ui.dzcolor.variant') + ':</b>&nbsp;&nbsp;{[values.rs[0].data.variant]}'
                    }),
                    loadMask: true,
                    renderTo: 'pLaunchingGridList'
                });
                
                pLaunchingListStore.load();
                
              });
              
              var validateForm = new Ext.FormPanel({
                  labelAlign: 'left',
                  url: '../../servlet/ProductLaunchingServlet?action=40',
                  frame: true,
                  bodyStyle: 'padding:5px 5px 5px 5px;margin-top: 2px;',
                  width: '100%',
                  labelWidth: 105,
                  //reader: piYarnXMLReader,
				  collapsible: true,
                  items: [{
                      id: 'plId',
                      name: 'id',
                      xtype: 'hidden'
                  }, {
                      id: 'biFactoryId',
                      name: 'biFactoryId',
                      xtype: 'hidden'
                  }, {
                      layout: 'column',
                      items: [{
                          columnWidth: .5,
                          layout: 'form',
                          items: [{
                              id: 'scheduleDate',
                              name: 'scheduleDate',
                              xtype: 'datefield',
                              fieldLabel: piMessage.get('ui.productidentification.scheduledate')+'(d/m/y)',
                              anchor: '86%',
							  width: '90%',
                              allowBlank: true
                          },{
								id: 'stockDate',
	                            name: 'stockDate',
	                            fieldLabel: piMessage.get('ui.productidentification.instockdate'),
	                            xtype: 'datefield',
	                            anchor: '86%',
								width: '90%',
	                            allowBlank: true
	                        },{
								id: 'factoryNameCN',
                                name: 'factoryNameCN',
                                fieldLabel: piMessage.get('ui.productidentification.stockplace'),
                                emptyText: message.get('message.combo.pleaseselect'),
                                xtype: 'textfield',
								readOnly: true,
                                anchor: '86%',
								width: '90%',
                                maxLength: 128,
                                listeners: {
                                    'render': {
                                        fn: function(){
                                            Ext.getCmp('factoryNameCN').getEl().on('click', function(){
                                                selectFactory(selectFactoryCallback, "'09'");
                                            }, this);
                                        },
                                        scope: this
                                    }
                                }
                                
                          }, {
                              id: 'factoryNameEN',
                              name: 'factoryNameEN',
                              fieldLabel: '',
                              labelSeparator:'',
                              xtype: 'textfield',
                              anchor: '86%',
                              allowBlank: true,
                              readOnly: true,
                              maxLength: 128
                          }]
                      }, {
                          columnWidth: .5,
                          layout: 'form',
                          items: [{
								id: 'quantity',
	                            name: 'quantity',
	                            fieldLabel: message.get('message.edit.quantity'),
	                            xtype: 'numberfield',
	                            anchor: '86%',
								width: '90%',
								readOnly: true,
	                            allowBlank: true
	                        },{
								  id: 'quantityConsistent',
	                              name: 'quantityConsistent',
	                              fieldLabel: piMessage.get('ui.productidentification.cquantity'),
	                              xtype: 'numberfield',
	                              //maxValue: Ext.getCmp('quantity').getValue(),
	                              anchor: '86%',
								  width: '90%',
	                              allowBlank: true,
	                              listeners: {
	                                    'render': {
	                                        fn: function(){
	                                            Ext.getCmp('quantityConsistent').getEl().on('click', function(){
	                                                Ext.getCmp('quantityConsistent').setValue(Ext.getCmp('quantity').getValue()-Ext.getCmp('quantityNotConsistent').getValue());
	                                            }, this);
	                                        },
	                                        scope: this
	                                    }
	                              }
	                          },{
								  id: 'quantityNotConsistent',
	                              name: 'quantityNotConsistent',
	                              fieldLabel: piMessage.get('ui.productidentification.cnquantity'),
	                              xtype: 'numberfield',
	                              //maxValue: Ext.getCmp('quantity').getValue(),
	                              anchor: '86%',
								  width: '90%',
	                              allowBlank: true,
	                              listeners: {
	                                    'render': {
	                                        fn: function(){
	                                            Ext.getCmp('quantityNotConsistent').getEl().on('click', function(){
	                                            	Ext.getCmp('quantityNotConsistent').setValue(Ext.getCmp('quantity').getValue()-Ext.getCmp('quantityConsistent').getValue());
	                                            }, this);
	                                        },
	                                        scope: this
	                                    }
	                              }
	                          }]
                      }]
                  }],
                  
                  buttons: [{
                      text: message.get('message.edit.save'),
                      handler: function(){
                    	  if(Ext.getCmp('quantityNotConsistent').getValue() > Ext.getCmp('quantity').getValue()){
                    		  messageTip.msg(message.get('message.tip'), message.get('message.edit.error'));
                    		  return;
                    	  }
                    	  if(Ext.getCmp('quantityConsistent').getValue() > Ext.getCmp('quantity').getValue()){
                    		  messageTip.msg(message.get('message.tip'), message.get('message.edit.error'));
                    		  return;
                    	  }
                          if (validateForm.getForm().isValid()) {
                              //document.getElementsByName('yarn')[0].value = yarnCombo.getValue();
                              
                              validateForm.getForm().submit({
                                  method: 'post',
                                  success: function(form, action){
                                      messageTip.msg(message.get('message.tip'), message.get('message.edit.successful'));
                                      validateForm.getForm().reset();
                                      pLaunchingListStore.load();
                                      validateWin.hide();
                                  },
                                  failure: function(form, action){
                                      messageTip.msg(message.get('message.tip'), message.get('message.edit.unsuccessful'));
                                  }
                              });
                          }
                      }
                  }, {
                      text: message.get('message.edit.reset'),
                      handler: function(){
                    	  Ext.getCmp('scheduleDate').setValue("");
                    	  Ext.getCmp('stockDate').setValue("");
                    	  Ext.getCmp('biFactoryId').setValue("");
                    	  Ext.getCmp('factoryNameCN').setValue("");
                    	  Ext.getCmp('factoryNameEN').setValue("");
                    	  //Ext.getCmp('quantity').setValue(Ext.getCmp('quantity1').getValue());
                    	  Ext.getCmp('quantityConsistent').setValue("");
                    	  Ext.getCmp('quantityNotConsistent').setValue("");
                      }
                  }, {
                      text: message.get('message.edit.cancel'),
                      handler: function(){
                    	  validateForm.getForm().reset();
                    	  validateWin.hide();
                      }
                  }]
              });
              
              function openValidateWin(id, scheduleDate, stockDate,biFactoryId,factoryNameCN,factoryNameEN,quantity1,quantityConsistent,quantityNotConsistent){
            	  if(!validateWin){
            		  validateWin = new Ext.Window({
                          title: message.get('message.action.validator'),
                          layout: 'fit',
                          width: 800,
                          height: 380,
                          closeAction: 'hide',
                          plain: true,
                          items: [validateForm]
                      });
            	  }
            	  Ext.getCmp('plId').setValue(id);
            	  Ext.getCmp('scheduleDate').setValue(scheduleDate);
            	  Ext.getCmp('stockDate').setValue(stockDate);
            	  Ext.getCmp('biFactoryId').setValue(biFactoryId);
            	  Ext.getCmp('factoryNameCN').setValue(factoryNameCN);
            	  Ext.getCmp('factoryNameEN').setValue(factoryNameEN);
            	  Ext.getCmp('quantity').setValue(quantity1);
            	  Ext.getCmp('quantityConsistent').setValue(quantityConsistent);
            	  Ext.getCmp('quantityNotConsistent').setValue(quantityNotConsistent);
            	  validateWin.show(this);
              };
              
              var selectFactoryCallback = function(factoryId, factoryName){
                  document.getElementById('biFactoryId').value = factoryId;
                  document.getElementById('factoryNameCN').value = selectedFactory.nameCN;
                  document.getElementById('factoryNameEN').value = selectedFactory.nameEN;
              }

              function renderIsStock(value, p, record){
	              if(!value){
		              value = '02';
	              }
	              //if(value == '01'){
	            	//  return String.format('<a href="javascript:addToStock({0}, \'{1}\');"><img src="../../images/icons/shading.png" title="' + piMessage.get('ui.productidentification.stock') + '" /><img width="10" src="../../images/icons/tick.png"></a>', record.id, value);
		          //}else{
		        	  return String.format('<a href="javascript:openValidateWin({0}, \'{1}\', \'{2}\');"><img src="../../images/icons/shading.png" title="' + piMessage.get('ui.productidentification.stock') + '" /><img width="10" src="../../images/icons/cross.png"></a>', record.id, record.data.scheduleDate,record.data.stockDate);
		          //}
              }
              
              function renderValidate(value, p, record){
            	  if(record.data.isStock == '01')
	            	  return String.format('<a href="javascript:openValidateWin({0}, \'{1}\', \'{2}\',\'{3}\', \'{4}\', \'{5}\',\'{6}\', \'{7}\', \'{8}\');"><img src="../../images/icons/product_in_progress_1.png" title="' + message.get('message.action.validator') + '" /></a>', 
	            	  			record.id, 
	            	  			record.data.scheduleDate,
	            	  			record.data.stockDate,
	            	  			record.data.biFactoryId,
	            	  			record.data.factoryNameCN,
	            	  			record.data.factoryNameEN,
	            	  			record.data.quantity1,
	            	  			record.data.quantityConsistent,
	            	  			record.data.quantityNotConsistent);
            	  else
            		  return String.format('<a href="javascript:openValidateWin({0}, \'{1}\', \'{2}\',\'{3}\', \'{4}\', \'{5}\',\'{6}\', \'{7}\', \'{8}\');"><img src="../../images/icons/product_in_progress_2.png" title="' + message.get('message.action.validator') + '" /></a>', 
	            	  			record.id, 
	            	  			record.data.scheduleDate,
	            	  			record.data.stockDate,
	            	  			record.data.biFactoryId,
	            	  			record.data.factoryNameCN,
	            	  			record.data.factoryNameEN,
	            	  			record.data.quantity1,
	            	  			record.data.quantityConsistent,
	            	  			record.data.quantityNotConsistent);
              }
              
        </script>
</head>
<body>
 <div id="productIdentification">
</div>
<div id="pLaunchingGridList">
</div>
</body>
</html>